package com.gurun.codes.business.home;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.gurun.codes.R;
import com.gurun.codes.databinding.ItemHomeContentListBinding;
import com.gurun.codes.utils.ScreenUtils;
import com.gurun.model.bean.home.GetRoomDeviceListResultBean;

class ContentListtemViewBinder extends me.drakeet.multitype.ItemViewBinder<GetRoomDeviceListResultBean.FamilyDevice, ContentListtemViewBinder.ViewHolder> {

    private Context mContext;
    private MainActivityTwo mActivity;

    public ContentListtemViewBinder(Context context,MainActivityTwo activity) {
        mContext = context;
        mActivity = activity;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_home_content_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull GetRoomDeviceListResultBean.FamilyDevice item) {
        holder.bindData(item);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private GetRoomDeviceListResultBean.FamilyDevice mData;
        ItemHomeContentListBinding mBinding;

        public ViewHolder(View itemView) {
            super(itemView);
            mBinding = DataBindingUtil.bind(itemView);
        }


        public void bindData(GetRoomDeviceListResultBean.FamilyDevice item) {
            mData = item;
            if (mData != null) {
                mBinding.setData(mData);
                mBinding.getRoot().setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (mActivity != null){
                            mActivity.onDeviceClicked(getAdapterPosition());
                        }
                    }
                });
            }
//            LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mBinding.ivDeviceIcon.getLayoutParams();
//            if (getAdapterPosition() == 0){
//                layoutParams.width = ScreenUtils.dp2px(mContext,80);
//                layoutParams.height = ScreenUtils.dp2px(mContext,80);
//            }else if (getAdapterPosition() == 1){
//                layoutParams.width = ScreenUtils.dp2px(mContext,80);
//                layoutParams.height = ScreenUtils.dp2px(mContext,80);
//            }else{
//                layoutParams.width = ScreenUtils.dp2px(mContext,50);
//                layoutParams.height = ScreenUtils.dp2px(mContext,50);
//            }
//            mBinding.ivDeviceIcon.setLayoutParams(layoutParams);
        }
    }
}
